package com.article.service.impl;

import com.article.service.MessageService;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * Created by Administrator on 2017/5/22.
 */
@Service("messageService")
public class MessageServiceImpl implements MessageService {
    @Resource(name = "jmsTemplate")
    private JmsTemplate jmsTemplate;

    //@Resource
    //private Destination queueDestination;

    @Override
    public void sendMessage(final String msg) {
//        System.out.println("要开始发送了消息啦-----------" + msg);
        String destination = jmsTemplate.getDefaultDestination().toString();
        System.out.println("向队列" + destination.toString() + "发送了消息------------" + msg);
        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(msg);
            }
        });
    }
}
